package com.yugao.fintech.draper.admin.controller;

import com.yugao.fintech.draper.auth.dto.ClientDetailsDTO;
import com.yugao.fintech.draper.admin.param.ClientDetailsQuery;
import com.yugao.fintech.draper.admin.service.Oauth2ClientDetailsService;
import com.yugao.fintech.draper.core.model.ResultVO;
import com.yugao.fintech.draper.security.annotation.SecurityInner;
import com.yugao.fintech.draper.datasource.entity.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/client")
@RequiredArgsConstructor
@Tag(name = "系统终端管理")
public class Oauth2ClientDetailsController {
	private final Oauth2ClientDetailsService oauth2ClientDetailsService;

	@Operation(summary = "查询客户终端分页列表")
	@GetMapping(value = "/page")
	@PreAuthorize("@ps.hasPermission('system:ClientDetails:view')")
	public ResultVO<PageResult<ClientDetailsDTO>> pageQuery(ClientDetailsQuery dto) {
		return ResultVO.success(PageResult.success(oauth2ClientDetailsService.pageQuery(dto)));
	}

	@Operation(summary = "添加客户终端")
	@PostMapping(value = "/add")
	@PreAuthorize("@ps.hasPermission('system:ClientDetails:add')")
	public ResultVO<Boolean> add(@RequestBody ClientDetailsDTO dto) {
		return ResultVO.success(oauth2ClientDetailsService.addClientDetails(dto));
	}

	@Operation(summary = "修改客户终端")
	@PostMapping(value = "/update")
	@PreAuthorize("@ps.hasPermission('system:ClientDetails:update')")
	public ResultVO<Boolean> update(@RequestBody ClientDetailsDTO dto) {
		return ResultVO.success(oauth2ClientDetailsService.updateClientDetails(dto));
	}

	@Operation(summary = "删除客户终端")
	@DeleteMapping(value = "/delete")
	@PreAuthorize("@ps.hasPermission('system:ClientDetails:delete')")
	public ResultVO<Boolean> delete(String id) {
		return ResultVO.success(oauth2ClientDetailsService.deleteClientDetails(id));
	}

	@SecurityInner(inner = true)
	@Operation(summary = "获取客户终端信息详情")
	@GetMapping(value = "/findById")
	public ResultVO<ClientDetailsDTO> findById(String id) {
		return ResultVO.success(oauth2ClientDetailsService.findById(id));
	}

	@Operation(summary = "获取全部客户终端")
	@GetMapping(value = "/findAll")
	@PreAuthorize("@ps.hasPermission('system:ClientDetails:view')")
	public ResultVO<List<ClientDetailsDTO>> findAll() {
		return ResultVO.success(oauth2ClientDetailsService.findAll());
	}

}